package com.jzo2o.health.controller.admin;


import com.alibaba.excel.EasyExcel;
import com.jzo2o.health.listener.uploadListener;
import com.jzo2o.health.model.excel.ReservationImportData;
import com.jzo2o.health.service.IReservationBatchSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 预约设置操作
 *
 * @author itcast
 */
@Slf4j
@RestController("adminReservationBatchSettingController")
@RequestMapping("/admin/reservation-setting")
@Api(tags = "管理端 - 批量预约设置相关接口")
public class ReservationBatchSettingController {

    @Resource
    private IReservationBatchSettingService reservationBatchSettingService;

    @PostMapping("/upload")
    @ApiOperation("上传文件批量预约设置")
    public void upload(@RequestPart("file") MultipartFile file) {
        log.info("读取预约文件：{}", file.getOriginalFilename());
        //读取excel
        try {
            EasyExcel.read(file.getInputStream(), ReservationImportData.class, new uploadListener(reservationBatchSettingService)).sheet().doRead();
        }
        catch (Exception ex) {
           log.error("读取文件失败",ex);
        }
//        List<ReservationImportData> reservationImportDataList = uploadListener.getReservationImportDataList();
//        reservationBatchSettingService.doImport(reservationImportDataList);
    }
}
